/**
 * 
 */
package com.yhty.web.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yhty.model.Rent;
import com.yhty.service.RentManager;

/**
 * 租房action
 * @author heq
 */
@Controller
@RequestMapping("/rent")
public class RentAction {
	
	private RentManager rentManager;
	
	@Resource(name="rentManager")
	public void setRentManager(RentManager rentManager) {
		this.rentManager = rentManager;
	}
	
	/**
	 * 房屋出租
	 * @param r
	 * @param model
	 */
	@RequestMapping(value="/add",method = RequestMethod.POST)
	public @ResponseBody
	Map<String, Object> add(Rent r,Model model){
		this.rentManager.rent(r);
		
		Map<String, Object> modelMap = new HashMap<String, Object>(1);
		modelMap.put("success", "true");
		return modelMap;
	}
	
	/**
	 * 房屋退房
	 * @param id
	 */
	@RequestMapping(value="/remove",method = RequestMethod.POST)
	public @ResponseBody
	Map<String, Object> remove(@RequestParam("rentid") Long id){
		this.rentManager.remove(id);
		
		Map<String, Object> modelMap = new HashMap<String, Object>(1);
		modelMap.put("success", "true");
		return modelMap;
	}
	
	/**
	 * 获取所有租房信息
	 */
	@RequestMapping(value = "/all", method = RequestMethod.GET)
	public @ResponseBody
	List<Rent> getAll(){
		List<Rent> rentList = this.rentManager.getAll();
		return rentList;
	}
}
